package com.xzq.daoimpl;

import java.io.Serializable;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.xzq.dao.AuthorityDao;
import com.xzq.entity.Authority;
import com.xzq.entity.Page;
import com.xzq.entity.page.PageSize;
import com.xzq.util.HibernatePage;
@Repository
public class AuthorityDaoImpl extends HibernatePage<Authority> implements AuthorityDao {

	@Override
	public List<Authority> findAllAuthority() {
		String hql = "from Authority";
		List<Authority> list = (List<Authority>) template.find(hql);
		return list;
	}

	@Override
	public Page findAllAuthorityByPage(Page page) {
		String hql = "from Authority";
		page = findHibernatePage(page, hql, null, PageSize.authSize);
		return page;
	}

	@Override
	public Authority findOneAuthority(Authority authority) {
		authority = template.get(Authority.class, authority.getId());
		return authority;
	}

	@Override
	public int modifyAuthority(Authority authority) {
		try {
			template.update(authority);
			return 1;
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}

	@Override
	public int addAuthority(Authority authority) {
		Serializable s = template.save(authority);
		int count = (Integer) s;
		return count;
	}

	@Override
	public int deleteAuthority(Authority authority) {
		try {
			template.delete(authority);
			return 1;
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}

}
